﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<List<CRM.Database.Model.TechnicRequests>>" %>
<%--<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<CRM.Models.TechnicRequests>>" %>--%>
<%@ Import Namespace="CRM.Resourses" %>



<% Html.DevExpress().GridView(settings =>
    {
        settings.Name = "gdTechnicRequests";
        settings.KeyFieldName = "IdTechnicRequest";
        settings.CallbackRouteValues = new { Controller = "TD", Action = "TechnicMyRequestsPartial" };
        settings.SettingsPager.PageSize = 20;
        settings.Settings.ShowGroupPanel = true;
        settings.Settings.ShowFilterRow = true;
        
        settings.Columns.Add(column =>
        {
            column.Caption = Resourses.TechnicRequestNumber;
            column.FieldName = "IdTechnicRequest";
            column.ColumnType = MVCxGridViewColumnType.HyperLink;
            column.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
            HyperLinkProperties properties = column.PropertiesEdit as HyperLinkProperties;
            String urlFormatString = Url.Action("TechnicRequestDetails", "TD", new RouteValueDictionary(new { idTecnicRequest = "{0}" }));
            properties.NavigateUrlFormatString = HttpUtility.UrlDecode(urlFormatString);
            properties.TextField = "IdTechnicRequest";
        });

        //Название клиента
        settings.Columns.Add(column =>
        {
            column.Caption = Resourses.TechnicCustomerName;
            column.FieldName = "CustomerName";
        });

        //классификация по обороту
        settings.Columns.Add(column =>
        {
            column.Caption = Resourses.TechnicCustomerClassificationByTurnover;
            column.FieldName = "CustomerClassificationByTurnover";
        });

        //Город
        settings.Columns.Add(column =>
        {
            column.Caption = Resourses.TechnicCity;
            column.FieldName = "City";
        });

        //манагер
        settings.Columns.Add(column =>
        {
            column.Caption = Resourses.TechnicManagerName;
            column.FieldName = "ManagerName";
        });

        //дата регистрицаа заявки
        settings.Columns.Add(column =>
        {
            column.Caption = Resourses.TrainingsRegisterDate;
            column.FieldName = "CreateDate";
            column.ColumnType = MVCxGridViewColumnType.DateEdit;
        });

        //типы выездов
        settings.Columns.Add(column =>
        {
            column.ColumnType = MVCxGridViewColumnType.Memo;
            column.Caption = Resourses.VisitsTypes;
            column.FieldName = "VisitsTypesColumn";
        });

        //техник
        settings.Columns.Add(column =>
        {
            column.Caption = Resourses.TechnicTechnicName;
            column.FieldName = "TechnicName";
        });

        //Дата выезда
        settings.Columns.Add(column =>
        {
            column.Caption = Resourses.TechnicPlannedDate;
            column.FieldName = "PlannedDateColumn";
        });

        //Статус заявки
        settings.Columns.Add(column =>
        {
            column.FieldName = "IdTechnicRequestStatus";
            column.Caption = Resourses.TrainingRequestsStatus;
            column.ColumnType = MVCxGridViewColumnType.ComboBox;
            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
            if (comboBoxProperties != null)
            {
                var col = new CRM.Database.Model.TechnicRequestStatusesCollection();
                comboBoxProperties.DataSource = col.TechnicRequestStatusesList;
                comboBoxProperties.TextField = "LocalizedName";
                comboBoxProperties.ValueField = "IdTechnicRequestStatus";
                //comboBoxProperties.DataSource = DB.GetLocalizedTechnicRequestStatusesNames(Thread.CurrentThread.CurrentCulture.ToString());
                //comboBoxProperties.TextField = "LocaLizedString";
                //comboBoxProperties.ValueField = "Id";
                comboBoxProperties.ValueType = typeof(int);
            }
        });

        //регион профайн
        settings.Columns.Add(column =>
        {
            column.Caption = Resourses.profineRegion;
            column.FieldName = "ProfineRegionNameLocalized";
        });

        //юр лицо
        settings.Columns.Add(column =>
        {
            column.Caption = Resourses.TechnicLegalEntityName;
            column.FieldName = "LegalEntityName";
        });
        
        //
        //Добавление редактирования
        //
        settings.CommandColumn.Visible = false;
        settings.CommandColumn.NewButton.Visible = false;
        settings.CommandColumn.DeleteButton.Visible = true;
        settings.CommandColumn.EditButton.Visible = false;
        settings.SettingsBehavior.ConfirmDelete = true;
        settings.Settings.ShowFilterRow = true;
        //settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "TC", Action = "TrainingsTrainersPartialUpdate" };
        //settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "TC", Action = "TrainingsTrainersPartialAdd" };
        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "TD", Action = "TechnicRequestsPartialDelete" };
        settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
        //settings.Width = Unit.Percentage(100);
    }).Bind(Model).GetHtml();%>